package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-number-of-non-overlapping-palindrome-substrings/
 * @create 2025/9/5 23:20
 * @since JDK17
 */

public class Solution85 {
    boolean f(String s) {
        for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
            if (s.charAt(i) != s.charAt(j)) {
                return false;
            }
        }
        return true;
    }

    public int maxPalindromes(String s, int k) {
        int n = s.length();
        int[] dp = new int[n + 1];
        for (int i = k; i <= n; i++) {
            for (int j = 0; j < i; j++) {
                if (f(s.substring(j, i))) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            dp[i] = Math.max(dp[i], dp[i - 1]);
        }

        return dp[n];
    }
}
